﻿/*
 * Thread.h
 *
 */
#ifndef __GDK_THREAD_H__
#define __GDK_THREAD_H__


#include <gdk/core/Types.h>

#ifdef _WIN32
#	include <windows.h>
#	include <process.h>
#else
#	include <pthread.h>
#endif

#include <gdk/core/System.h>
#include <gdk/core/Semaphore.h>
#include <gdk/core/Mutex.h>
#include <map>





namespace gdk
{




class GDK_CORE_EXPORT Thread : virtual public Unknown
{
	DECLARE_CLASS_HANDLE(Thread)
	DECLARE_CLASS_INSTANCE(Thread)

private:
	Mutex mutable		_mutex;
	System::Handle		_system;
	Semaphore::Handle	_initSemaphore;

#ifdef _WIN32
	HANDLE				_threadId;
#else
	pthread_t			_threadId;
#endif


protected:
	Thread(void);
	virtual ~Thread(void);

public:
	System::Handle getSystem(void) const;

private:
#ifdef _WIN32
	static unsigned int __stdcall main(void *pThread);
#else
	static void* main(void *pThread);
#endif

public:
	virtual bool start(System *system);
	virtual bool shutdown(void);
};




}//namespace gdk



#endif /*__GDK_THREAD_H__*/
